home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / strings / charcont.asm next >
Encoding:
Assembly Source File  |  1989-05-03  |  1.2 KB  |  49 lines

  1. ;unsigned short  char_count(strg,character);
  2. ;  unsigned char  *strg,character;
  3.  
  4.     EXTRN  _memory_model:byte
  5.  
  6. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  7.     ASSUME CS:_TEXT
  8.     PUBLIC _char_count
  9. _char_count proc near
  10.     push bp            ;
  11.     mov  bp,sp        ;set up stack frame
  12.     push si            ;
  13.     push ds            ;
  14.     cmp  _memory_model,0    ;near or far?
  15.     jle  begin        ;jump if near
  16.     inc  bp            ;else add 2 to BP
  17.     inc  bp            ;
  18. begin:    cmp  _memory_model,2    ;data near or far?
  19.     jb   L0            ;jump if near
  20.     lds  si,dword ptr [bp+4] ;point DS:SI to string
  21.     inc  bp            ;add 2 to BP since dword ptr
  22.     inc  bp            ;
  23.     jmp  short L00        ;
  24. L0:    mov  si,[bp+4]        ;
  25. L00:    sub  bx,bx        ;BX counts chars
  26.     mov  cx,bx        ;clear CX
  27.     mov  al,[bp+6]        ;search char
  28.     cmp  byte ptr[si],0    ;test for null string
  29.     je   L3            ;
  30. L1:    mov  dl,[si]        ;get the character
  31.     cmp  dl,0        ;test for end of string
  32.     je   L3            ;
  33.     cmp  dl,al        ;
  34.     jne  L2            ;jmp if not the char
  35.     inc  bl            ;else, increment the ctr
  36. L2:    inc  si            ;inc ptr for next time
  37.     jmp  short L1        ;loop
  38. L3:    mov  ax,bx        ;set result for return
  39.     pop  ds            ;
  40.     pop  si            ;
  41.     pop  bp            ;restore BP
  42.     cmp  _memory_model,0    ;quit
  43.     jle  quit        ;
  44.     db   0CBh        ;RET far
  45. quit:    ret            ;RET near
  46. _char_count ENDP
  47. _TEXT    ENDS
  48.     END
  49.